package com.example.ui.contact.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.huashangapp.R;
import com.example.ui.contact.bean.PraiseItem;
import com.example.util.BitmapLoad;
import com.example.util.Util;

public class PraiseAdapter extends BaseAdapter{
	private List<PraiseItem> msgList = new ArrayList<PraiseItem>();// 消息对象数组
	private Context mContext;
	private LinearLayout noticeLayout;	
	public PraiseAdapter(Context mContext,LinearLayout noticeLayout,List<PraiseItem> msgList){
		this.mContext = mContext;
		this.msgList = msgList;
		this.noticeLayout = noticeLayout;
	}
	@SuppressWarnings("deprecation")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null; 
		convertView=null;
		if(convertView==null){
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.chat_comment_item, null);
			holder.headImg = (ImageView)convertView.findViewById(R.id.chat_comment_item_head);
			holder.nameText = (TextView)convertView.findViewById(R.id.chat_comment_item_name);
			holder.title = (TextView)convertView.findViewById(R.id.chat_comment_item_comment_text);//赞了我的：（这个字段是不变的 ）
			holder.content = (TextView)convertView.findViewById(R.id.chat_comment_item_comment_content);
			holder.contentText = (TextView)convertView.findViewById(R.id.personhome_listview_item_content_text);
			holder.contentImg1 = (ImageView)convertView.findViewById(R.id.personhome_listview_item_content_photo1);
			holder.contentImg2 = (ImageView)convertView.findViewById(R.id.personhome_listview_item_content_photo2);
			holder.contentImg3 = (ImageView)convertView.findViewById(R.id.personhome_listview_item_content_photo3);
			holder.contentTime = (TextView)convertView.findViewById(R.id.chat_comment_item_comment_time);
			convertView.setTag(holder);
		}else{
			holder = (Holder)convertView.getTag();
		}
		Bitmap bit = null;
		String imgUrl = msgList.get(position).getHeadPic();
		String name = msgList.get(position).getName();
		if(imgUrl!=null){
			bit=BitmapLoad.loadBitmap(mContext,imgUrl);
			Drawable dra = new BitmapDrawable(bit);
			holder.headImg.setBackgroundDrawable(dra);
		}else{
			Util.toast(mContext, "网络连接有误，请重试");
			holder.headImg.setBackgroundResource(R.drawable.wall_bg);
		}
		//holder.headImg.setBackgroundResource(R.drawable.head_bg);
		holder.nameText.setText(name);
		holder.title.setText("赞了我的： ");//赞了我的：（这个字段是不变的 ）
		holder.content.setVisibility(View.GONE);//这个字段隐藏掉，不用显示了
		holder.contentText.setText("原文内容显示在这里");
		holder.contentImg1.setVisibility(View.VISIBLE);
		holder.contentImg2.setVisibility(View.VISIBLE);
		holder.contentImg3.setVisibility(View.VISIBLE);
		holder.contentTime.setText("今天  09:41");
		
		return convertView;
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	
	@Override
	public int getCount() {
		if(msgList.size()==0){
			noticeLayout.setVisibility(View.VISIBLE);
			return 0;
		}
		noticeLayout.setVisibility(View.GONE);
		return msgList.size();
	}
	
	class Holder {
		ImageView headImg;
		TextView nameText;
		TextView title;//赞了我的:(这个字是不变的)
		TextView content;//评论内容
		
		TextView contentText;//原文内容
		ImageView contentImg1;//原文图片1
		ImageView contentImg2;//原文图片2
		ImageView contentImg3;//原文图片3

		TextView contentTime;//评论时间
	}

}
